﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Openfree.Framework.DataAccess;

public partial class SiteAdmin_DemoPage : SiteAdminBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //string cmdText = "select CRIMINAL_NO,CRIMINAL_NAME,GENDER_CODE,BIRTHDATE,REG_ADDRESS,REPORT_TIME from T_WFFZ_RYXX";
            string cmdText = "select Subject,CreateDate from T_Document order by CreateDate";
            FillGirdView(0, cmdText);
            //this.searchFree.InitData();
        }
        else
        {
            FillGirdView(this.gridView.SplitPageIndex, string.Empty);
        }
    }

    protected void FillGirdView(int currentPage, string cmdText)
    {
        if (string.IsNullOrEmpty(cmdText))
        {
            cmdText = ViewState[this.ClientID + "cmdText"].ToString();
        }
        ViewState[this.ClientID + "cmdText"] = cmdText;
        SqlConnection conn = new SqlConnection();
        using (conn)
        {
            conn.ConnectionString = "Data Source=.;Initial Catalog=Openfree;Persist Security Info=True;User ID=sa;Password=as";
            conn.Open();
            SqlSplitPage splitPage = new SqlSplitPage(conn, cmdText);
            splitPage.PageSize = 10;
            DataSet ds = splitPage.LoadDataSet(currentPage);
            gridView.ShowFooter = true;
            gridView.NavigationData = splitPage.GetNavigationData(currentPage, Openfree.Framework.WebControl.SplitPageStyle.Complex);
            gridView.SplitPageStyle = Openfree.Framework.WebControl.SplitPageStyle.Complex;
            gridView.DataSource = ds.Tables[0];
            gridView.DataBind();
            conn.Close();
            
        }
    }    


    protected void gridView_SplitPageIndexChange(object sender, CommandEventArgs e)
    {
        FillGirdView(Int32.Parse(e.CommandArgument.ToString()), ViewState[this.ClientID + "cmdText"].ToString());
    }
}
